package com.ocom.srvpamh.controller;

import com.alibaba.fastjson.JSON;
import com.ocom.common.constant.MachineHttpUrl;
import com.ocom.common.dto.PerInfoDto;
import com.ocom.common.entity.access.EntityMjDeviceInfoExtend;
import com.ocom.common.entity.card.EntityCardInfo;
import com.ocom.common.request.srvpaccess.UpdateAvatarRequest;
import com.ocom.common.resp.RespMachMessage;
import com.ocom.common.resp.Result;
import com.ocom.common.response.wx.MachInfoPageOnShowResponse;
import com.ocom.common.utils.CommonUtil;
import com.ocom.common.utils.DateUtil;
import com.ocom.common.utils.JsonResponse;
import com.ocom.common.utils.StateCode;
import com.ocom.common.vo.recode.DoorRecodeVo;
import com.ocom.common.vo.srvpaccess.UserDeptInfoVo;
import com.ocom.redis.util.RedisUtil;
import com.ocom.srvpamh.business.YkmHandleService;
import com.ocom.srvpamh.feignclient.*;
import com.ocom.srvpamh.service.MachineService;
import com.ocom.srvpamh.service.PinganbaiyunService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
public class MachineController {

    private Logger logger = LoggerFactory.getLogger(MachineController.class);


    @Autowired
    private AiotClientService aiotClientService;

    @Autowired
    private SrvpaccessClientService srvpaccessClientService;

    @Autowired
    private PayConfigClientService payConfigClientService;

    @Autowired
    private AccessClientService accessClientService;

    @Autowired
    private MjRecodeFeignService mjRecodeFeignService;

    @Resource
    private RedisUtil redisUtil;

    @Autowired
    private MachineService machineService;

    @Autowired
    private YkmHandleService ykmHandleService;

    @Autowired
    PinganbaiyunService pinganbaiyunService;
    /*
     * @Description: 心跳
     * @Author: lu
     * @Date: 2022/4/6 9:02
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_PostSign)
    public JsonResponse sign(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.sign(map);
        return jsonResponse;
    }

    @PostMapping(MachineHttpUrl.URL_PostHeartbeat)
    public JsonResponse heartbeat(@RequestBody Map<String,Object> map) {

        String machno="";


        try{
            machno= (String) map.get("machNo");
            String versionCode=(String) map.get("versionCode");
            Integer saasNo  = (Integer) redisUtil.hmGet("HttpMjDevice:" + machno, "saasNo");
            if(saasNo == 10 || saasNo==11){
                //返回
                Map<String,Object> resMap=new HashMap<>();
                resMap.put("paramUpdate",0);
                resMap.put("accontimeUpdate",0);
                resMap.put("acconpermissionUpdate",0);
                resMap.put("listUpdate",0);
                resMap.put("keyUpdate",0);
                resMap.put("nowTime", DateUtil.getDateTime());
                resMap.put("JKMlistUpdate", 0);
                resMap.put("updateWhiteInfo", 0);
                //固件  Aiot调用
                RespMachMessage respMachMessageAiot=aiotClientService.GetMjDeviceVersion(machno,versionCode,2);

//            logger.info("心跳#Aiot请求:请求参数:【{}】,返回参数:【{}】",machno,respMachMessageAiot);
                if(!respMachMessageAiot.getCode().equals("0000") && !respMachMessageAiot.getCode().equals("0014")){
                    return JsonResponse.error(StateCode.companyIdCod,StateCode.companyIdMsg);
                }
                Map<String,Object> objectMap2=(Map<String, Object>) JSON.parse(JSON.toJSONString(respMachMessageAiot.getData()));
                if(!respMachMessageAiot.getCode().equals("0014")){
                    resMap.put("firmwareUpdate",objectMap2.get("firmwareUpdate"));
                }else{
                    resMap.put("firmwareUpdate",0);
                }
//            resMap.put("firmwareUpdate",0);
                Integer firmwareUpdate = (Integer) resMap.get("firmwareUpdate");
                if (firmwareUpdate==1){
                    return JsonResponse.success((String) objectMap2.get("apkUrl"),resMap);
                }else {
                    return JsonResponse.success(resMap);
                }
            }

        }catch (Exception e){
            logger.info("心跳异常 【】",e);
        }



        try {
            machno= (String) map.get("machNo");

            //返回
            Map<String,Object> resMap=new HashMap<>();

            Integer companyId = (Integer) redisUtil.hmGet("HttpMjDevice:"+machno, "companyId");
            String versionCode=(String) map.get("versionCode");
            //分库查找
            RespMachMessage respMachMessage=srvpaccessClientService.getDeviceFlag(companyId.longValue(),machno,versionCode,1);
//            logger.info("心跳#分库请求:请求参数:【{}】,返回参数:【{}】",machno,respMachMessage);

//            logger.info("respMachMessage="+respMachMessage);
            if(!respMachMessage.getCode().equals("0000")){
                return JsonResponse.error(StateCode.companyIdCod,StateCode.companyIdMsg);
            }

            Map<String,Object> objectMap= (Map<String, Object>) JSON.parse(JSON.toJSONString(respMachMessage.getData()));

            resMap.put("paramUpdate",objectMap.get("paramUpdate")==null?0:objectMap.get("paramUpdate"));
            resMap.put("accontimeUpdate",objectMap.get("accontimeUpdate"));
            resMap.put("acconpermissionUpdate",objectMap.get("acconpermissionUpdate"));
            resMap.put("listUpdate",objectMap.get("listUpdate"));
            resMap.put("keyUpdate",objectMap.get("keyUpdate"));
            resMap.put("nowTime", DateUtil.getDateTime());

//            //TODO  获取设备的片区Id
//            Integer reginId = 0;
//            try {
//                RespMachMessage result=srvpaccessClientService.getReginIdByMach(companyId.longValue(),machno);
//                reginId=(Integer) result.getData();
//            }catch (Exception e){
//                logger.info("心跳#获取片区:【{}】,请求方式:【{}】,请求参数:【{}】,返回参数:【{}】",machno,"获取片区",map,e.getMessage());
//            }
//            Long size=redisUtil.lGetListSize("timerCompany:"+companyId+":"+reginId);
//
//            //  是否拉取健康码
//            if(size.intValue()>0){
//                resMap.put("JKMlistUpdate", 1);
//            }else{
                resMap.put("JKMlistUpdate", 0);
//            }

            try {
                EntityMjDeviceInfoExtend entityMjDeviceInfoExtend=new EntityMjDeviceInfoExtend();
                entityMjDeviceInfoExtend.setComId(companyId.longValue());
                entityMjDeviceInfoExtend.setDeviceNo(machno);
                RespMachMessage<EntityMjDeviceInfoExtend> result=srvpaccessClientService.getDeviceExtend(entityMjDeviceInfoExtend);
                resMap.put("updateWhiteInfo", result.getData().getUpdateWhiteInfo());
            }catch (Exception e){
            }

            //固件  Aiot调用
            RespMachMessage respMachMessageAiot=aiotClientService.GetMjDeviceVersion(machno,versionCode,2);

//            logger.info("心跳#Aiot请求:请求参数:【{}】,返回参数:【{}】",machno,respMachMessageAiot);
            if(!respMachMessageAiot.getCode().equals("0000") && !respMachMessageAiot.getCode().equals("0014")){
                return JsonResponse.error(StateCode.companyIdCod,StateCode.companyIdMsg);
            }
            Map<String,Object> objectMap2=(Map<String, Object>) JSON.parse(JSON.toJSONString(respMachMessageAiot.getData()));
            if(!respMachMessageAiot.getCode().equals("0014")){
                  resMap.put("firmwareUpdate",objectMap2.get("firmwareUpdate"));
            }else{
                resMap.put("firmwareUpdate",0);
            }
//            resMap.put("firmwareUpdate",0);
            Integer firmwareUpdate = (Integer) resMap.get("firmwareUpdate");
            if (firmwareUpdate==1){
                return JsonResponse.success((String) objectMap2.get("apkUrl"),resMap);
            }else {
                return JsonResponse.success(resMap);
            }
        }catch (Exception e){
            logger.info("心跳#异常记录:请求参数:【{}】,返回异常:【{}】",machno,e);
            return JsonResponse.error();
        }
    }


    @PostMapping(MachineHttpUrl.URL_PostMachineEntranceRecord)
    public JsonResponse recode(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse;
        String machno="";

        try {
            machno= (String) map.get("machNo");
            Integer recordId= (Integer) map.get("recordId");

            Integer operateType= (Integer) map.get("operateType");
            String accessTime= (String) map.get("accessTime");
            String yct= (String) map.get("yct");
            String data= (String) map.get("data");
//            Integer openStatus= (Integer) map.get("openStatus");
            Integer openStatus= 1;
            if(map.get("openStatus")!=null){
                openStatus =  (Integer) map.get("openStatus");
            }

            Integer companyId = (Integer) redisUtil.hmGet("HttpMjDevice:"+machno, "companyId");

            DoorRecodeVo doorRecodeVo=new DoorRecodeVo();

            if(data!=null){
                doorRecodeVo.setYct(data);
            }

//            if(companyId==526){
                //海口一中门禁记录上传 【{accessTime=2023-04-24 17:22:06, checkStatus=, color=, data=, idnum=11345, openStatus=3, operateType=1, pictureUrl=http://193.112.157.241:9002/yan/2023/04/24/e76bf64d8bf547f1adb1132a922a3a1c_11345_11345_62204130040046116823281267523254_1682328126995.jpg, recordId=11286, temperature=0.0, type=3, yct=, comMode=1, lastServerTime=78, lastTranTime=0, machNo=622041300400461, sessionId=TmElOxefpB, versionCode=1.1.3_u202FMD_mj, versionKernel=4.9.113, companyID=526, ipAddr=36.101.142.45}】
//                logger.info("海口一中门禁记录上传 【{}】",map);
//            }



            String temperature = (String) map.get("temperature");
            String pictureUrl = (String) map.get("pictureUrl");

            String checkStatus="200";

            Integer type =1;
            String idnum ="";


            try {
//                if (null != map.get("checkStatus") && StringUtils.isNotBlank(map.get("checkStatus").toString())) {
//                    checkStatus = map.get("checkStatus").toString();
//                }

                type = (Integer) map.get("type");
                if(type == 4){
                    idnum =  (String) map.get("idnum");
                }
                doorRecodeVo.setPId(0);
                if(type==1){
                    String idnum1 = (String) map.get("idnum");
                    Result cardInfoByCardNo = payConfigClientService.getCardInfoByCardNo(companyId.longValue(), idnum1);
                    if (200 == cardInfoByCardNo.getCode() && null != cardInfoByCardNo.getData()) {
                        EntityCardInfo entityCardInfo  = JSON.parseObject(JSON.toJSONString(cardInfoByCardNo.getData()), EntityCardInfo.class);
                        if (null != entityCardInfo && null != entityCardInfo.getPId()) {
                            doorRecodeVo.setPId(entityCardInfo.getPId().intValue());
                        }
                    }
                    if (0 == doorRecodeVo.getPId()) {
                        RespMachMessage respMachMessage = srvpaccessClientService.getPersonInfoByCard(companyId.longValue(),idnum1);
                        if (respMachMessage.getCode().equals("0000")) {
                            UserDeptInfoVo userDeptInfoVo =JSON.parseObject(JSON.toJSONString(respMachMessage.getData()),UserDeptInfoVo.class);
                            if (null != userDeptInfoVo && null != userDeptInfoVo.getPId()) {
                                doorRecodeVo.setPId(userDeptInfoVo.getPId());
                                doorRecodeVo.setPCode(userDeptInfoVo.getPCode());
                                doorRecodeVo.setDeptId(userDeptInfoVo.getDeptId());
                                doorRecodeVo.setDeptName(userDeptInfoVo.getDeptName());
                                doorRecodeVo.setPName(userDeptInfoVo.getPName());
                            }
                        }
                    }

                }else{
                    doorRecodeVo.setPId(Integer.valueOf( (String) map.get("idnum")));
                }
            }catch (Exception e){
                logger.info("门禁记录#异常#解析checkStatus异常:【{}】,请求方式:【{}】",machno,"上传门禁记录-异常",map,e);
            }

            //开门类型。（0 未知 ，1：进入  2：离开）
            doorRecodeVo.setOpenState(0);

            try {
                String key = "GetMachineInfoById:" + companyId + ":" + machno;
                Object o = redisUtil.get(key);
                if(o!=null){
                    MachInfoPageOnShowResponse machInfoPageOnShowResponse =(MachInfoPageOnShowResponse) o;
                    doorRecodeVo.setOpenType(machInfoPageOnShowResponse.getOpenType());
                    doorRecodeVo.setDeviceName(machInfoPageOnShowResponse.getMachName());
                }else{
                    Result<MachInfoPageOnShowResponse> result1 = accessClientService.getMachineInfoById(companyId.longValue(), machno);
                    if (result1.getCode() == 200) {
                        // 获取设备出入方式
                        logger.info("获取设备出入方式 {}", result1);
                        redisUtil.set(key, result1.getData(), 600l);
                        doorRecodeVo.setOpenType(result1.getData().getOpenType());
                        doorRecodeVo.setDeviceName(result1.getData().getMachName());
                    }
                }
            } catch (Exception e) {
                logger.error("解析设备信息 JSON 错误", e);
            }


            doorRecodeVo.setComId(companyId);
            doorRecodeVo.setData(data);
            doorRecodeVo.setDeviceNo(machno);
            doorRecodeVo.setOpenTime(accessTime);
            if(operateType==5 || operateType==6)  operateType=1;
            doorRecodeVo.setOpenMode(operateType);
            doorRecodeVo.setRecodeId(recordId.toString());

            if(!CommonUtil.isNull(idnum)){
                doorRecodeVo.setPCode(idnum);
            }

            doorRecodeVo.setCheckStatus(checkStatus);

            doorRecodeVo.setTemperature(CommonUtil.isNull(temperature)?"":temperature);
            doorRecodeVo.setAvatarUrl(CommonUtil.isNull(pictureUrl)?"":pictureUrl);


            RespMachMessage respMachMessage2 = srvpaccessClientService.getPersonInfoByPId(companyId.longValue(),doorRecodeVo.getPId().longValue());
            if (respMachMessage2.getCode().equals("0000")) {
                PerInfoDto perInfoDto = JSON.parseObject(JSON.toJSONString(respMachMessage2.getData()),PerInfoDto.class);
                doorRecodeVo.setPName(perInfoDto.getPName());
                doorRecodeVo.setPCode(perInfoDto.getPCode());
                doorRecodeVo.setDeptId(perInfoDto.getDeptId().intValue());
                doorRecodeVo.setDeptName(perInfoDto.getDeptName());
                doorRecodeVo.setPPhone(perInfoDto.getPPhone());
            }

            boolean b=ykmHandleService.HandleYct(doorRecodeVo);
            if(!b){
                return JsonResponse.error();
            }

        }catch (Exception e){
            logger.info("门禁记录#异常#机器号:【{}】,请求方式:【{}】",machno,"上传门禁记录-异常",map,e);
            return JsonResponse.error();
        }
        return  JsonResponse.success(null);
    }


    /*
     * @Description:设备参数更新
     * @Author: lu
     * @Date: 2022/4/12 10:21
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_PostMachinePara)
    public JsonResponse MachinePara(@RequestBody Map<String,Object> map) {
        String machno = "";
        try {
            machno = (String) map.get("machNo");
            Integer companyId = (Integer) redisUtil.hmGet("HttpMjDevice:"+machno, "companyId");
            map.put("companyId", companyId);
            RespMachMessage respMachMessage = srvpaccessClientService.getMachPara(companyId.longValue(), machno);
            logger.info("设备参数更新:【{}】,请求方式:【{}】", machno, respMachMessage);
            if (respMachMessage.getCode().equals("0000")) {
                return JsonResponse.success(respMachMessage.getData());
            } else {
                return JsonResponse.error(respMachMessage.getCode(), respMachMessage.getMsg());
            }
        } catch (Exception e) {
            logger.info("设备参数更新#异常#机器号:【{}】,请求方式:【{}】", machno, "设备参数更新-异常", map, e);
            return JsonResponse.error();
        }
    }

    /**
     * 健康码名单更新
     * @param map
     * @return
     */
//    @PostMapping(MachineHttpUrl.URL_PostMachineJKMList)
//    public JsonResponse JKMList(@RequestBody Map<String,Object> map) {
//        JsonResponse jsonResponse;
//        String machno = "";
//        try {
//            machno = (String) map.get("machNo");
//            Integer companyId = (Integer) redisUtil.hmGet(machno, "companyId");
//            Integer limit= (Integer) map.get("listLimit");
//
//            logger.info("健康码名单更新# 单位:【{}】,机器号:【{}】,请求参数:【{}】",companyId,machno,"上传门禁记录-参数",map);
//
//            //TODO  获取设备的片区Id
//            Integer reginId = 0;
//            try {
//                RespMachMessage result=srvpaccessClientService.getReginIdByMach(companyId.longValue(),machno);
//                reginId=(Integer) result.getData();
//            }catch (Exception e){
//                logger.info("获取身份证列表#获取片区:【{}】,请求方式:【{}】,请求参数:【{}】,返回参数:【{}】",machno,"获取身份证列表",map,e.getMessage());
//            }
//
//            Gson gson=new Gson();
//
//            List<Map> list =new ArrayList<>();
//            for (int i=0;i<limit;i++){
//                Object o=redisUtil.rightPop("timerCompany:"+companyId+":"+reginId);
//                if(o!=null){
//                    Map<String,String> map1=gson.fromJson((String) o,Map.class);
//                    list.add(map1);
//                }else{
//                    break;
//                }
//            }
//            //返回
//            Map<String,Object> resMap=new HashMap<>();
//            resMap.put("list",list);
//            jsonResponse=JsonResponse.success(resMap);
//            return jsonResponse;
//        }catch (Exception e){
//            logger.info("健康码名单更新#异常#机器号:【{}】,异常:【{}】",machno,"上传门禁记录-异常",map,e);
//            return JsonResponse.error();
//        }
//    }

//    @PostMapping(MachineHttpUrl.URL_PostMachineJKMListResult)
//    public JsonResponse JKMListResult(@RequestBody Map<String,Object> map) {
//        return JsonResponse.success();
//    }

    /*
     * @Description:设备参数更新通知结果
     * @Author: lu
     * @Date: 2022/4/15 8:53
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_PostMachineParaResult)
    public JsonResponse changeMachParaState(@RequestBody Map<String,Object> map) {
        String machno = "";
        try {
            machno = (String) map.get("machNo");
            Integer result= (Integer) map.get("result");
            if (result==0){
                Integer companyId = (Integer) redisUtil.hmGet("HttpMjDevice:"+machno, "companyId");
                map.put("companyId", companyId);
                String jobId=(String) map.get("jobId");
                RespMachMessage respMachMessage = srvpaccessClientService.changeMachParaState(companyId.longValue(), machno,jobId);
                logger.info("设备参数更新结果通知#机器号:【{}】,请求方式:【{}】,请求参数:【{}】,返回参数:【{}】",machno,"上传门禁记录",map,respMachMessage);
                if (respMachMessage.getCode().equals("0000")) {
                    return JsonResponse.success(respMachMessage.getData());
                } else {
                    return JsonResponse.error(respMachMessage.getCode(), respMachMessage.getMsg());
                }
            }else {
                Map<String,Object> objectMap=new HashMap<>();
                objectMap.put("updataFlag",0xff);
                return JsonResponse.success(objectMap);
            }
        } catch (Exception e) {
            logger.info("设备参数更新结果通知异常#机器号:【{}】,请求方式:【{}】,请求参数:【{}】,返回参数:【{}】",machno,"上传门禁记录",map,e);
            return JsonResponse.error();
        }
    }

    /*
     * @Description:个人信息上传
     * @Author: lu
     * @Date: 2022/4/29 13:54
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_JKMIdentityCard)
    public JsonResponse JKMIdentityCard(@RequestBody Map<String,Object> map) {
        JsonResponse jsonResponse=machineService.JKMIdentityCard(map);
        return jsonResponse;
    }

    /**
     * 白名单更新 (WhiteList)
     *
     * @return*/
    @PostMapping(MachineHttpUrl.URL_WhiteList)
    public JsonResponse WhiteList(@RequestBody Map<String,Object> map){
        return machineService.WhiteList(map);
    }

    /**
     * 白（黑）名单更新结果（WhiteListResult)
     *
     * @return*/
    @PostMapping(MachineHttpUrl.URL_WhiteListResult)
    public JsonResponse WhiteListResult(@RequestBody Map<String,Object> map){
        return machineService.WhiteListResult(map);
    }


    /**
     * 在线认证开门（CertificationOpenDoor )
     *
     * @return*/
    @PostMapping(MachineHttpUrl.URL_CertificationOpenDoor)
    public JsonResponse CertificationOpenDoor(@RequestBody Map<String,Object> map){
        return machineService.CertificationOpenDoor(map);
    }

    /**
     * 获取门禁权限组（AuthorityGroup )
     *
     * @return*/
    @PostMapping(MachineHttpUrl.URL_AuthorityGroup)
    public JsonResponse AuthorityGroup(@RequestBody Map<String,Object> map){
        return machineService.AuthorityGroup(map);
    }


    /**
     * 在线认证开门（TimeZone )
     *
     * @return*/
    @PostMapping(MachineHttpUrl.URL_TimeZone)
    public JsonResponse TimeZone(@RequestBody Map<String,Object> map){
        return machineService.TimeZone(map);
    }

    /**
     * 在线认证开门（TimeZoneResult )
     *
     * @return*/
    @PostMapping(MachineHttpUrl.URL_TimeZoneResult)
    public JsonResponse TimeZoneResult(@RequestBody Map<String,Object> map){
        return machineService.TimeZoneResult(map);
    }

    /**
     * 离线码解码密钥更新（DecodeKey )
     *
     * @return*/
    @PostMapping(MachineHttpUrl.URL_DecodeKey)
    public JsonResponse DecodeKey(@RequestBody Map<String,Object> map){
        return machineService.DecodeKey(map);
    }

    /**
     * 离线码解码密钥更新结果（DecodeKeyResult )
     *
     * @return*/
    @PostMapping(MachineHttpUrl.URL_DecodeKeyResult)
    public JsonResponse DecodeKeyResult(@RequestBody Map<String,Object> map){
        return machineService.DecodeKeyResult(map);
    }


    /*
     * @Description: 平安码
     * @Author: zhuhui
     * @Date: 2022年12月8日10:08:39
     * @param map:
     * @return: com.ocom.common.utils.JsonResponse
     **/
    @PostMapping(MachineHttpUrl.URL_ThirdPartyCodeReport)
    public JsonResponse UserCode(@RequestBody Map<String,Object> map) {
        String machno = "";
        try {
            String content = (String) map.get("data");
            Integer type = (Integer) map.get("type");
            return pinganbaiyunService.getUserInfo(content);
        } catch (Exception e) {
            logger.info("设备参数更新结果通知异常#机器号:【{}】,请求方式:【{}】,请求参数:【{}】,返回参数:【{}】",machno,"上传门禁记录",map,e);
            return JsonResponse.error();
        }
    }



    @PostMapping(MachineHttpUrl.URL_pictureurl)
    public JsonResponse pictureurl(@RequestBody Map<String,Object> map) {
        String machno="";

        try {
            machno= (String) map.get("machNo");
            String recordId= (String) map.get("recordId");
            String recDate= (String) map.get("recDate");
            String avatarUrl= (String) map.get("url");
            Integer companyId = (Integer) redisUtil.hmGet("HttpMjDevice:"+machno, "companyId");
            UpdateAvatarRequest request =new UpdateAvatarRequest();
            request.setComId(companyId);
            request.setMachNo(machno);
            request.setId(recordId);
            request.setAvatarUrl(avatarUrl);
            request.setMonthValue(recDate.replace("-","").substring(0,6));
            mjRecodeFeignService.updateAvatar(request);
            return JsonResponse.success(recordId);
        } catch (Exception e) {
            logger.info("设备参数更新结果通知异常#机器号:【{}】,请求方式:【{}】,请求参数:【{}】,返回参数:【{}】",machno,"上传门禁记录",map,e);
            return JsonResponse.error();
        }
    }




    @PostMapping(MachineHttpUrl.URL_updateWhiteInfo)
    public JsonResponse updateWhiteInfo(@RequestBody Map<String,Object> map) {
        String machno = "";
        try {
            machno = (String) map.get("machNo");

            Integer companyId = (Integer) redisUtil.hmGet("HttpMjDevice:"+machno, "companyId");
            map.put("companyId", companyId);

            EntityMjDeviceInfoExtend entityMjDeviceInfoExtend=new EntityMjDeviceInfoExtend();
            entityMjDeviceInfoExtend.setComId(companyId.longValue());
            entityMjDeviceInfoExtend.setDeviceNo(machno);
            entityMjDeviceInfoExtend.setWhiteUrl((String) map.get("whiteUrl"));
            entityMjDeviceInfoExtend.setWhiteUser((Integer) map.get("whiteUser"));
            entityMjDeviceInfoExtend.setWhiteFace((Integer) map.get("whiteFace"));
            entityMjDeviceInfoExtend.setWhiteErrFace((Integer) map.get("whiteErrFace"));
            entityMjDeviceInfoExtend.setUpdateWhiteInfo(0);
            RespMachMessage respMachMessage = srvpaccessClientService.updateDeviceExtend(entityMjDeviceInfoExtend);
            logger.info("设备参数更新结果通知#机器号:【{}】,请求方式:【{}】,请求参数:【{}】,返回参数:【{}】",machno,"上传门禁白名单信息",map,respMachMessage);
            if (respMachMessage.getCode().equals("0000")) {
                return JsonResponse.success(respMachMessage.getData());
            } else {
                return JsonResponse.error(respMachMessage.getCode(), respMachMessage.getMsg());
            }
        } catch (Exception e) {
            logger.info("设备更新白名单信息异常#机器号:【{}】,请求方式:【{}】,请求参数:【{}】,返回参数:【{}】",machno,"上传门禁记录",map,e);
            return JsonResponse.error();
        }
    }


}
